//返回分页结果,接收一个页码参数,liId用于改变选择后li的样式, type_id用于记录当前登录用户级别;postPage 提交的页面
function pagination(divid, pageId, liId, postPage){
	$(".flash").show();
	$(".flash").fadeIn(500).html('Loading <img src="resource/image/ajax-loading.gif" />');
	var dataString = 'pageId=' + pageId;

	$.post(postPage, {"pageId":pageId}, function(data){
		//删除除th以外所有的tr
		$("#"+ divid +" tr:gt(0)").remove();
		$(".link a").css('background-color','lightblue') ;

		$("#" + divid).html($("#" + divid).html() + data);
		
		$("#"+liId+" a").css('background-color','#99A607') ;

		$(".flash").hide();
	});
}

//接收一个id为divname的div，然后在该div中显示页码;第二参数:在哪里显示分页信息 infoDivnam格式必须为：'"infoDivnam"';第三参数:ajax的页面
function pageData(divname, infoDivnam, postPage, postPage2){
	/*
	/*有缺陷，将全部显示所有页码
	*/
	$.post(postPage, {}, function(data){
		//分页条数,返回内容条数
		var PAGE_PER_NO = data[0];
		var item = data[1];
				
		//页数
		var page = 0;
				
		var html = "<ul>";

		if(item != 0){
			//first、last标签
					
			var first = 0;
			var last = 0;

			var pagec = item/PAGE_PER_NO;

			if(Math.floor(pagec) == 0){
				//不足一页
				first = last;
				page = 1;
			}else{
				if(item%PAGE_PER_NO == 0){
					//条数刚好达到分页
					page = pagec;
				}else{
					page = Math.floor(pagec) + 1;
				}
				last = page - 1;
			}
			
			//编辑first标签
			html += "<li id="+ '"first"' +" class='link'><a href='javascript:void(0)' onclick='pagination("+ infoDivnam +", 0,"+ '"first",' + postPage2 +");'>First</a></li>";
			
			for(var i = 0; i < page; i++){
				var pagenum = i + 1;
				//html += "<li id=" + i + ">" + pagenum + "</li>";
				html += "<li id="+ i +" class='link'><a href='javascript:void(0)' onclick='pagination("+ infoDivnam +", "+ i +","+ '"' + i +'",' + postPage2 +");'>"+ pagenum +"</a></li>";
			}
			//编辑last标签
			html += "<li id="+ '"last"' +" class='link'><a href='javascript:void(0)' onclick='pagination("+ infoDivnam +", " + last +","+ '"last",' + postPage2 +");'>Last</a></li><li class='flash'></li>";

			html += "</ul>";	
		}else{
			html = "没有数据";
		}
		$("#" + divname).html(html);
	}, "json")
}